package com.ruoyi.creditlife.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.creditlife.domain.CreditLifeBehavior;
import com.ruoyi.system.domain.CreditUserInfo;
import com.ruoyi.creditlife.mapper.CreditLifeBehaviorMapper;
import com.ruoyi.system.mapper.CreditUserInfoMapper;
import com.ruoyi.creditlife.service.ICreditLifeBehaviorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CreditLifeBehaviorServiceImpl implements ICreditLifeBehaviorService
{
    @Autowired
    private CreditLifeBehaviorMapper creditLifeBehaviorMapper;

    @Autowired
    private CreditUserInfoMapper creditUserInfoMapper;

    @Override
    public CreditLifeBehavior selectCreditLifeBehaviorById(Long id) {
        return creditLifeBehaviorMapper.selectCreditLifeBehaviorById(id);
    }

    @Override
    public List<CreditLifeBehavior> selectCreditLifeBehaviorList(CreditLifeBehavior creditLifeBehavior) {
        return creditLifeBehaviorMapper.selectCreditLifeBehaviorList(creditLifeBehavior);
    }

    @Override
    public int insertCreditLifeBehavior(CreditLifeBehavior creditLifeBehavior) {
        return creditLifeBehaviorMapper.insertCreditLifeBehavior(creditLifeBehavior);
    }

    @Override
    public int updateCreditLifeBehavior(CreditLifeBehavior creditLifeBehavior) {
        return creditLifeBehaviorMapper.updateCreditLifeBehavior(creditLifeBehavior);
    }

    @Override
    public int deleteCreditLifeBehaviorByIds(Long[] ids) {
        return creditLifeBehaviorMapper.deleteCreditLifeBehaviorByIds(ids);
    }

    @Override
    public int deleteCreditLifeBehaviorById(Long id) {
        return creditLifeBehaviorMapper.deleteCreditLifeBehaviorById(id);
    }

    @Override
    public List<CreditLifeBehavior> selectCreditLifeBehaviorByUserId(Long id) {
        return creditLifeBehaviorMapper.selectCreditLifeBehaviorByUserId(id);
    }

    @Override
    public int ImpactCreditScore(Long userId, int score) {
        CreditUserInfo userInfo = creditUserInfoMapper.selectCreditUserInfoByUserId(userId);
        if (userInfo != null) {
            userInfo.setCreditScore(userInfo.getCreditScore() + score);
            return creditUserInfoMapper.updateCreditUserInfo(userInfo);
        }
        return 0;
    }
}